//输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）
//示例 1：
//输入：head = [1,3,2]
//输出：[2,3,1]
package main
import "fmt"
type ListNode struct {
	Val  int
	Next *ListNode
}
type Stack struct {
	Val []int
}
func (stk *Stack) pop() int { // 必须使用引用传递
	return stk.Val[len(stk.Val)-1]
}
func (stk *Stack) push(v int ) {
	stk.Val = append(stk.Val, v)
}
func reversePrint(head *ListNode) []int {
	var stk Stack
	var ARRVal []int
	for ; head!= nil; {
		stk.push(head.Val)
		head = head.Next
	}
	for i := len(stk.Val) - 1; i > -1; i-- {
		ARRVal = append(ARRVal, stk.Val[i])
	}
	return ARRVal
}

func main(){
	var l1 ListNode
	var l2 ListNode
	var l3 ListNode
	l1.Next=&l2
	l2.Next=&l3
	l1.Val=1
	l2.Val=3
	l3.Val=2
	fmt.Println(reversePrint(&l1))
}